﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class TimChuyen : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {        
        if (!Page.IsPostBack)
        {
            //QLVe v = new QLVe();
            //ddlDiemdi.DataSource = v.getAllTinh();
            //ddlDiemdi.DataBind();
            //ddlDiemden.DataSource = v.getAllTinh();
            //ddlDiemden.DataBind();
            loadTinh();
        }
    }

    public void loadTinh()
    {
        ConnectionDB db = new ConnectionDB();
        db.Cmd.CommandText = "select * from TinhThanh";
        SqlDataAdapter adap = new SqlDataAdapter(db.Cmd);
        DataSet ds = new DataSet();
        adap.Fill(ds);
        ddlDiemden.DataSource = ds;
        ddlDiemden.DataTextField = "ten_tinhthanh";
        ddlDiemden.DataValueField = "ma_tinhthanh";
        ddlDiemden.DataBind();

        ddlDiemdi.DataSource = ds;
        ddlDiemdi.DataTextField = "ten_tinhthanh";
        ddlDiemdi.DataValueField = "ma_tinhthanh";
        ddlDiemdi.DataBind();
    }
    protected void btnTimchuyen_Click(object sender, ImageClickEventArgs e)
    {
        ConnectionDB db = new ConnectionDB();
        db.Cmd.CommandType = CommandType.StoredProcedure;
        db.Cmd.CommandText = "timchuyen";
        db.Cmd.Parameters.AddWithValue("@diemdi",ddlDiemdi.SelectedValue);
        db.Cmd.Parameters.AddWithValue("@diemden", ddlDiemden.SelectedValue);
        db.Cmd.Parameters.AddWithValue("@ngaydi", txtFromDate.Text);
        SqlDataAdapter adap = new SqlDataAdapter(db.Cmd);
        DataSet ds = new DataSet();
        adap.Fill(ds);
        gvTimchuyen.DataSource = ds;
        gvTimchuyen.DataBind();

        
    }
    protected void gvTimchuyen_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (Session["username"] == null)
            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "Warning", "alert('Khách hàng phải đăng nhập !!')", true);
        else
        {
            if (e.CommandName == "Datve")
            {
                int RowIndex = int.Parse(e.CommandArgument.ToString());
                string id = gvTimchuyen.Rows[RowIndex].Cells[0].Text;
                Session["cid"] = id;
                Response.Redirect("~/DatVePage.aspx");
            }
        }
    }
}